package com.wolfking.converter.event;

import com.wolfking.jeesite.entity.SignEvent;
import com.wolfking.jeesite.listener.AbstractSignEventListener;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class SqlQueryEventListener extends AbstractSignEventListener<SqlQueryEvent> {

    @Override
    public void onApplicationEvent(SqlQueryEvent event) {
        SignEvent signEvent = event.convert2SignEvent();
        String defineKey = event.getParameters().getOrDefault("defineKey", "").toString();
        if (StringUtils.isNoneBlank(defineKey)) {
            signEvent.setUrl(defineKey);
            try {
                signEvent.setEvent(Class.forName(signEvent.getEvent()).getSimpleName());
            } catch (Exception e) {
                logger.warn("e", e);
            }
        }
        saveSysSignEvent(signEvent);
    }
}
